<template>
  <div>
    <div class="basic-layout">
      <div :class="['nav-side', isCollapse?'fold': 'unfold']">
        <!-- 系统菜单 -->
        <div class="logo">
          <img src="./../assets/logo.png" alt="" />
          <span v-if="!isCollapse">后台管理系统</span>
        </div>
        <!-- 导航菜单 -->
        <el-menu
          :default-active="activeMenu"
          class="nav-menu"
          router
          text-color="#fff"
          background-color="#001529"
          active-text-color="#ffddba"
          :collapse="isCollapse"
        >
        <!-- {{activeMenu}} -->
        <menu-tree />
        </el-menu>
      </div>
      <div :class="['content-right', isCollapse? 'fold': 'unfold']">
        <div class="nav-top">
          <div class="nav-top-left">
            <el-icon @click="toggleMenuCollapse"><fold /></el-icon>
            <div class="bread">
              <BreadCrumb />
            </div>
          </div>
          <div class="nav-top-right">
            <el-badge is-dot class="item"
              ><el-icon :size="30" class="bell"><bell /></el-icon
            ></el-badge>
            <el-dropdown @command="handleCommand">
              <span class="user-info">
                {{ userInfo.userName || ''}}<el-icon class="el-icon--right"><arrow-down /></el-icon>
              </span>

              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item command="email"
                    >邮箱: {{ userInfo.userEmail || '' }}</el-dropdown-item
                  >
                  <el-dropdown-item command="logout">退出</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
        <div class="wrapper">
          <div class="home-main">
            <router-view></router-view>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import MenuTree from "./MenuTree.vue";
import BreadCrumb from "./BreadCrumb.vue";
export default {
  name: "Home",
  components: {
    MenuTree,BreadCrumb
  },
  data() {
    return {
      isCollapse: false,
      userInfo: this.$store.state.userInfo,
      activeMenu: location.hash.slice(1)
    };
  },
  methods: {
    handleCommand(command) {
      if (command == "email") return;
      this.$store.commit("saveUserInfo", "");
      this.userInfo = { userName: "", email: "" };
      this.$router.push("/login");
    },
    toggleMenuCollapse(){
      this.isCollapse = !this.isCollapse;
    },
  },
};
</script>

<style lang="scss">
.basic-layout {
  position: relative;
  .nav-side {
    position: fixed;
    background-color: #001529;
    height: 100vh;
    width: 200px;
    color: #fff;
    overflow-y: auto;
    transition: width 0.5s;
    .logo {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 15px;
      height: 50px;
      img {
        width: 32px;
        height: 32px;
        margin: 0 10px;
      }
    }
    .nav-menu {
      border-right: none;
      height: calc(100vh - 50px);
    }

    // 收缩
    &.fold{
      width: 80px;
    }
    // 展开
    &.unfold{
      width: 200px;
    }
  }
  .content-right {
    margin-left: 200px;
    /* background-color: #dedede; */
    .nav-top {
      height: 50px;
      line-height: 50px;
      padding: 0 20px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #a5a5a5;
      .nav-top-left {
        display: flex;
        align-items: center;
        .el-icon {
          margin-right: 15px;
          font-size: 20px;
        }
      }
      .nav-top-right {
        .item {
          margin-right: 20px;
          /* font-size: 40px; */
          .el-badge__content.is-fixed.is-dot {
            right: 5px;
            top: 15px;
          }
          .bell{
            top: 10px
          }
        }
        .user-info{
          cursor: pointer;
          color: #001529;
        }
      }
    }
    .wrapper {
      background-color: #d3d3dd;
      height: calc(100vh - 50px);
      /* padding: 20px; */
      color: #fff;
      .home-main {
        height: 100%;
        /* background-color: #fff; */
        color: #000;
      }
    }

    &.fold{
      margin-left: 80px;
    }
    &.unfold{
      margin-left: 200px;
    }
  }
}
</style>
